﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MvvmLib;

namespace MathFlowLib
{
    /// <summary>
    /// 算法流基类
    /// </summary>
    public abstract class Vm_MathFlow_Base<TParam, TOutput> : Vm_Base, IMathFlow
        where TParam : Vm_MathFlow_Param, new()
        where TOutput : Vm_MathFlow_Output, new()
    {
        #region NotifyProperty

        /// <summary>
        /// 算法参数
        /// </summary>
        public TParam Param
        {
            get { return _Param; }
            set
            {
                if (_Param != value)
                {
                    _Param = value;
                    this.OnPropertyChanged("Param");
                }
            }
        }
        private TParam _Param;

        /// <summary>
        /// 代号
        /// </summary>
        public abstract string CodeName { get; }

        #endregion

        #region Methods

        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="param">算法参数</param>
        public Vm_MathFlow_Base(TParam param)
        {
            Param = param;

            Init();
        }

        /// <summary>
        /// 初始化方法
        /// </summary>
        public void Init()
        {
            Vir_Init();
        }

        /// <summary>
        /// 运行方法
        /// </summary>
        /// <param name="output"></param>
        public void Run(Vm_MathFlow_Output output)
        {
            if (output is TOutput)
            {
                TOutput toutput = output as TOutput;
                Vir_Run(toutput);
            }
            else
            {
                throw new Exception("结果类型错误");
            }

        }

        /// <summary>
        /// 算法初始化方法
        /// </summary>
        public abstract void Vir_Init();


        /// <summary>
        /// 算法运行方法
        /// </summary>
        public abstract void Vir_Run(TOutput output);


        #endregion

    }
}